﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using System.Xml.Serialization;

namespace SEOSitemap
{
    [Serializable()]
    [XmlRoot("sitemapindex", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
    public class SiteMapIndexDocument
    {
        private List<SiteMapItem> _siteMapItems;

        [XmlElement("sitemap")]
        public List<SiteMapItem> SiteMapItems
        {
            get { return _siteMapItems; }
            set { _siteMapItems = value; }
        }

        private string _fileName;

        [XmlIgnore]
        public string FileName
        {
            get { return _fileName; }
            set { _fileName = value; }
        }

        public void SaveAllToFile()
        {
            File.WriteAllText(FileName, ToXml());
            foreach (SiteMapItem siteMap in SiteMapItems)
            {
                siteMap.SiteMapDocument.SaveToFile();
            }
        }


        public void SaveToFile()
        {
            File.WriteAllText(FileName, ToXml());
        }

        public string ToXml()
        {
            return Helper.ToXml(this);
        }
    }
}
